<template>
	<view>
		<view class="uni-container" style="float: left;">
            <span>猜对多少歌曲增加一次提现机会(大转盘机会)</span>
			<uni-forms ref="form" validateTrigger="bind">
				<uni-forms-item label="需要猜对歌曲数" name="title" labelWidth="150">
					<input class="uni-input-border" type="number" v-model="tixiannum.liandui" style="width: 200px;"/>
				</uni-forms-item>
				<view class="uni-button-group pointer">
					<button class="uni-button uni-button-full" type="primary" :disabled="isLoading" @click="save">保存</button>
				</view>
			</uni-forms>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isLoading:false,
				"tixiannum":{
					"liandui": 0
				}
			}
		},
		mounted() {
			this.getinfo()
		},
		methods: {
			getinfo(){
				this.isLoading = true
				uni.showLoading({
					title: '加载中'
				});
				uniCloud.callFunction({
					name: 'uni-admin',
					data: {
						action: "admin/loadconfig",
						data: {
							id: 'tixiannum'
						}
					}
				}).then((res) => {
					console.log(res, "get--------------")
					this.tixiannum = res.result.config
					uni.hideLoading();
				}).catch((res) => {
					console.log(res)
				}).finally(err => {
					this.isLoading = false
					uni.hideLoading();
				})
			},
			save(){
				this.isLoading = true
				delete this.tixiannum._id;
				for(let key in this.tixiannum){
					if(key != '_id'){
						this.tixiannum[key] = Number(this.tixiannum[key])
					}
				}
				console.log(this.tixiannum)
				
				uni.showLoading({
					title: '保存中'
				});
				uniCloud.callFunction({
					name: 'uni-admin',
					data: {
						action: "admin/setconfig",
						data: {
							json: JSON.stringify({
								tixiannum:this.tixiannum
							})
						}
					}
				}).then((res) => {
					console.log(res, "res--------------")
					this.isLoading = false
					uni.hideLoading();
					uni.showToast({
						title: "修改成功",
						icon: 'none',
						duration: 2000
					})
				}).catch((res) => {
					console.log(res)
				}).finally(err => {
					this.isLoading = false
					uni.hideLoading();
				})
				
			}
		}
	}
</script>

<style>

</style>
